package com.hzncc.scaffold.controller.other;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzncc.scaffold.entity.Vo.GenerateCertVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzncc.scaffold.core.ResultT;
import com.hzncc.scaffold.service.OneplusxrecordService;
import com.hzncc.scaffold.entity.Other.Oneplusxrecord;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 1+X考试记录表 前端控制器
 * </p>
 *
 * @author DrunkBear
 * @since 2022-04-27
 */
@RestController
@RequestMapping("/oneplusxrecord")
@Api(tags = "1+X考试记录表接口")
public class OneplusxrecordController {

    @Resource
    private OneplusxrecordService oneplusxrecordService;

    /**
     * 查询表中所有信息
     *
     * @return
     */
    @GetMapping
    @ApiOperation("查询所有1+X考试记录表中数据")
    public ResultT findAll() {
        return ResultT.success(oneplusxrecordService.list());
    }

    /**
     * 根据Id查询表中数据
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据Id查询1+X考试记录表中数据")
    public ResultT findOne(@PathVariable Integer id) {
        return ResultT.success(oneplusxrecordService.getById(id));
    }

    /**
     * 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询1+X考试记录表中数据")
    public ResultT findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        QueryWrapper<Oneplusxrecord> queryWrapper = new QueryWrapper<>();
        return ResultT.success(oneplusxrecordService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

    /**
     * 新增和更新接口
     *
     * @param
     * @return
     */
    @PostMapping
    @ApiOperation("新增或更新1+X考试记录表中数据")
    public ResultT save(@RequestBody Oneplusxrecord oneplusxrecord) {
        oneplusxrecordService.saveOrUpdate(oneplusxrecord);
        return ResultT.success();
    }

    /**
     * 根据Id删除表中数据
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据Id删除1+X考试记录表中数据")
    public ResultT delete(@PathVariable Integer id) {
        oneplusxrecordService.removeById(id);
        return ResultT.success();
    }

    /**
     * 批量删除表中数据
     *
     * @param ids
     * @return
     */
    @PostMapping("/del/batch")
    @ApiOperation("批量删除1+X考试记录表中数据")
    public ResultT deleteBatch(@RequestBody List<Integer> ids) {
        oneplusxrecordService.removeByIds(ids);
        return ResultT.success();
    }

    @PostMapping("/queryByEntity")
    @ApiOperation("条件查询")
    public ResultT queryByEntity(Oneplusxrecord oneplusxrecord) {
        LambdaQueryWrapper<Oneplusxrecord> lqw = new LambdaQueryWrapper<>();
        lqw.eq(oneplusxrecord.getId() != null, Oneplusxrecord::getId, oneplusxrecord.getId());
        lqw.eq(oneplusxrecord.getUserId() != null, Oneplusxrecord::getUserId, oneplusxrecord.getUserId());
        lqw.eq(oneplusxrecord.getActivityId() != null, Oneplusxrecord::getActivityId, oneplusxrecord.getActivityId());
        lqw.eq(oneplusxrecord.getTheoryScore() != null, Oneplusxrecord::getTheoryScore, oneplusxrecord.getTheoryScore());
        lqw.eq(oneplusxrecord.getOperationScore() != null, Oneplusxrecord::getOperationScore, oneplusxrecord.getOperationScore());
        lqw.eq(oneplusxrecord.getAverageScore() != null, Oneplusxrecord::getAverageScore, oneplusxrecord.getAverageScore());
        lqw.eq(oneplusxrecord.getPassed() != null, Oneplusxrecord::getPassed, oneplusxrecord.getPassed());
        lqw.eq(oneplusxrecord.getExamTime() != null, Oneplusxrecord::getExamTime, oneplusxrecord.getExamTime());
        lqw.eq(oneplusxrecord.getCreateTime() != null, Oneplusxrecord::getCreateTime, oneplusxrecord.getCreateTime());
        lqw.eq(oneplusxrecord.getType() != null, Oneplusxrecord::getType, oneplusxrecord.getType());

        List<Oneplusxrecord> oneplusxrecordList = oneplusxrecordService.list(lqw);
        return ResultT.success(oneplusxrecordList);
    }



}
